package com.luoxiang.socialandroid.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import com.blankj.utilcode.util.ScreenUtils
import com.luoxiang.socialandroid.R
import com.luoxiang.socialandroid.databinding.DialogWechatBinding

/**
 * Author: fuxinbo

 * Date: 2023/2/11

 * Description:
 */
class WeChatDialog @JvmOverloads constructor(
    context: Context,
    themeResId: Int = R.style.Dialog
) :
    Dialog(context, themeResId) {

    var onClose: () -> Unit = {}

    var onPay: (isEnable : Boolean) -> Unit = {}

    private var isEnable : Boolean = false

    private val binding: DialogWechatBinding by lazy {
        DialogWechatBinding.inflate(
            layoutInflater
        )
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        initView()
        initDialog()
    }

    fun setCoinNum(coin: Int, isEnable: Boolean = true) {
        this.isEnable = isEnable
        binding.textWeChatCoin.text = "是否支付${coin}金币，查看她的微信号码！"
    }

    private fun initView() {
        binding.textClose.setOnClickListener {
            hide()
            onClose.invoke()
        }
        binding.textPay.setOnClickListener {
            onPay.invoke(isEnable)
        }
    }

    /**
     * 初始化弹窗属性
     *
     */
    private fun initDialog() {
        context.let {
            val dialogWindow: Window? = this.window
            dialogWindow?.setGravity(Gravity.CENTER)
            val lp: WindowManager.LayoutParams? = dialogWindow?.attributes
            lp?.height = WindowManager.LayoutParams.WRAP_CONTENT
            lp?.width = ScreenUtils.getScreenWidth() - (32 * 4)
            dialogWindow?.setAttributes(lp)
        }
    }
}